package sweetguy.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import sweetguy.dto.PermissionInsertDTO;
import sweetguy.dto.PermissionUpdateDTO;
import sweetguy.dto.PageDTO;
import sweetguy.service.PermissionService;

import java.util.List;

@Tag(name = "权限模块")
@RestController
@RequestMapping("/api/v1/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @Operation(summary = "添加一条记录")
    @PostMapping("/save")
    public Object save(@RequestBody @Validated PermissionInsertDTO roomInsertDTO) {
        return permissionService.insert(roomInsertDTO);
    }

    @Operation(summary = "查询一条记录")
    @GetMapping("/getInfo/{id}")
    public Object getInfo(@PathVariable Long id) {
        return permissionService.selectById(id);
    }

    @Operation(summary = "修改一条记录")
    @PostMapping("/update")
    public Object updateById(@RequestBody @Validated PermissionUpdateDTO permissionUpdateDTO) {
        return permissionService.updateById(permissionUpdateDTO);
    }

    @Operation(summary = "逻辑删除一条记录")
    @PostMapping("/remove/{id}")
    public Object remove(@PathVariable Long id) {
        return permissionService.logicDeleteById(id);
    }

    @Operation(summary = "批量删除记录")
    @PostMapping("/removeBatch")
    public Object removeBatch(@RequestParam List<Long> ids) {
        return permissionService.logicDeleteByIds(ids);
    }

    @Operation(summary = "全查询记录")
    @GetMapping("/list")
    public Object list() {
        return permissionService.list();
    }

    @Operation(summary = "分页查询记录")
    @PostMapping("/page")
    public Object page(@RequestBody @Validated PageDTO pageDTO) {
        return permissionService.page(pageDTO);
    }
}
